﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DCT.Huiteng.Utility.Web;
using DCT.Huiteng.AdminSystem.Web.Codes;

namespace DCT.Huiteng.AdminSystem.Web.WebAPIs
{
    public class CreateSSOTokenWebAPI : IWebAPI
    {
        public void Process(WebAPIContext context)
        {
            var cp = context.MakeResponse();
            string token = "";
            bool runerror = false;
            if (SSOTokenValidator.Generate(out token, out runerror))
            {
                cp.SetVal("token", token);
            }
            else {
                if (!runerror)
                {
                    cp.SetVal("error", "004001");
                    cp.SetVal("error_desc", "request invalid");
                }
                else {
                    cp.SetVal("error", "004002");
                    cp.SetVal("error_desc", "run error");
                }
            }
            context.ResponseConfigParser(cp);
        }
    }
}